package link.anyauto.dtbinding.util;

import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

/**
 * Created by LYQ on 2016/7/26.
 */
public class BindUtils {

    @BindingAdapter("imgUrl")
    public static void setImage(ImageView image, String imgUrl) {
        Picasso.with(image.getContext()).load(imgUrl).into(image);
    }

    @BindingAdapter("imgUrl")
    public static void setImage(ImageView image, int imgUrl) {
//         这里也可用picasso
//        Picasso.with(image.getContext()).load(imgUrl).into(image);
        image.setImageResource(imgUrl);
    }

    // 可以创建多个参数的适配器，如下，必须要同时有 imgUrl="", err="", loading=""三个属性才会调用这个方法
    @BindingAdapter({"imgUrl", "err", "loading"})
    public static void setImage(ImageView image, String imgUrl, Drawable err, Drawable loading) {
        Picasso.with(image.getContext()).load(imgUrl).error(err).placeholder(loading).into(image);
    }
}
